package com.tang.filecenter.controller;

import com.tang.filecenter.dto.ImageListDto;
import com.tang.filecenter.service.IGalleryService;
import com.tang.filecenter.vo.ImageVo;
import com.tang.filecenter.vo.PageVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Api(tags = "图库")
@RestController
@RequestMapping("/gallery")
public class GalleryController {
    @Autowired
    private IGalleryService galleryService;
    @ApiOperation("获取图片")
    @GetMapping("/get/{name}")
    public void get(@PathVariable String name, HttpServletResponse response) throws IOException {
        galleryService.get(name, response);
    }

    @ApiOperation("上传图片")
    @PostMapping("/upload")
    public String upload(MultipartFile file) throws IOException {
        return galleryService.upload(file);
    }

    @ApiOperation("删除图片")
    @GetMapping("/delete/{name}")
    public void delete(@PathVariable String name) throws IOException {
        galleryService.delete(name);
    }

    @ApiOperation("分页查询图片")
    @PostMapping("/pageList")
    public PageVo<ImageVo> pageList(@RequestBody ImageListDto dto) throws IOException {
        return galleryService.pageList(dto);
    }

    @ApiOperation("上传博客图片")
    @PostMapping("/uploadForBlog")
    public String uploadForBlog(@RequestParam Integer blogId, @RequestParam MultipartFile file) throws IOException {
        return galleryService.uploadForBlog(blogId,file);
    }

}
